<template>
	<view class="contain">
		<view class="fixed">
			<cu-custom :isBack="false" :color="color" bgColor="bg-shadeTop" @goBack="goBack">
				<block slot="content">
					<!--<view class="content">上传参数</view>-->
					<view class="content">{{lang.upload.transpara}}</view>
				</block>
			</cu-custom>
		</view>
		<view class="list">
			<!--<input class="title" type="text" v-model="val" placeholder="请输入标题">-->
			<input class="title" type="text" v-model="val" :placeholder="lang.upload.inputtitle">
			<scroll-view class="nav" scroll-y="true">
				<view class="nav-item" v-for="(v,k) in listStr" :key="k">
					<view>{{v.parameterName + '='}}</view>
					<!--<input class="msg" type="text" v-model="v.realvalue" placeholder="请输入值" :disabled="v.groupNum.substring(0,2) == 'MC' ? true : false" @blur="getData(k,v)">-->
					<input class="msg" type="text" v-model="v.realvalue" :placeholder="lang.upload.inputvalue" :disabled="v.groupNum.substring(0,2) == 'MC' ? true : false" @blur="getData(k,v)">
				</view>
			</scroll-view>
			<textarea class="text" v-model="textStr" disabled></textarea>
			<!--<view class="btn1" @tap="goRefresh">点击上传</view>-->
			<view class="btn1" @tap="goRefresh">{{lang.upload.clickcommit}}</view>
		</view>
	</view>
</template>

<script>
	import {mapState, mapMutations} from "vuex";
	import Toast from '../../common/toast.js'
	export default {
		data() {
			return {
				color: '#333',
				text: '',
				listStr: [],
				textStr: '',
				val: '',
				names: '',
				state: true,
				paramsExplain:[]
			}
		},
		computed: {
			...mapState(["lang"])
		},
		onLoad() {
			let list = this.$store.state.sortList;
			this.listStr = this.$store.state.sortList;
			this.listStr.forEach((item,index) => {
				this.textStr += '//' + item.parameterName + ' ' + item.parameterDescription + '\n';
				let obj={
					parameterNumber:item.parameterNumber,
					paramsExplain:item.parameterName.split('_')[0]+ ' ' + item.parameterDescription +'='+item.realvalue
				}
				this.paramsExplain.push(obj);
			})
			// console.log(this.listStr)
			console.log(this.paramsExplain)
			console.log(list)
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			getData(k,item) {
				let min = item.deviation;
				let max = (Math.pow(2, item.bitLength) - 1) / item.coefficientK + Number(item.deviation);
				if(this.listStr[k].value === '') {
					//Toast.showToast('输入值不能为空')
					Toast.showToast(this.lang.upload.inputvaluenull)
					this.state = false
					return
				}
				if(this.listStr[k].value < parseFloat(min)) {
					//Toast.showToast('输入值超出下限')
					Toast.showToast(this.lang.upload.inputovermin)
					this.state = false
					return
				}
				if(this.listStr[k].value > parseFloat(max)) {
					//Toast.showToast('输入值超出上限')
					Toast.showToast(this.lang.upload.inputovermax)
					this.state = false
					return
				}
			},
			goRefresh() {
				if(this.val == '') {
					//Toast.showToast('请填写标题')
					Toast.showToast(this.lang.upload.writetitle)
					return
				}
				if(!this.state) {
					//Toast.showToast('参数输入有误')
					Toast.showToast(this.lang.upload.paraerror)
					return
				}
				uni.showLoading({
					//title: "上传中..."
					title: this.lang.upload.commiting
				});
				let dataList = this.$store.state.paramList;
				let paramsExplain=[];
				console.log(dataList)
				let data1 = {
					title: this.val,
					paramsContent: JSON.stringify(this.listStr),
					paramsExplain:JSON.stringify(this.paramsExplain),
					identification: dataList
				}
				this.$u.post('authc/api/user/upload_file', data1).then(res => {
					console.log(res)
					uni.hideLoading();
					if(res.code == 0) {
						//Toast.showToast('上传成功')
						Toast.showToast(this.lang.upload.commitsucc)
						setTimeout(() => {
							uni.navigateBack()
						},500)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.contain {
		width: 100%;
		height: 100vh;
		background: #FFFFFF;
		display: flex;
		flex-direction: column;
		align-items: center;
		overflow: hidden;
		
		.fixed {
			width: 100%;
		
			.content {
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
		}
		
		.list {
			width: 100%;
			padding: 0 28rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			
			.title {
				width: 100%;
				height: 80rpx;
				padding: 24rpx;
				box-sizing: border-box;
				background: #F1F1F1;
				margin-bottom: 30rpx;
				border-radius: 6px;
				font-size: 28rpx;
				color: #333;
			}
			
			.nav {
				width: 100%;
				height: 400rpx;
				padding: 24rpx;
				box-sizing: border-box;
				background: #F1F1F1;
				margin-bottom: 30rpx;
				border-radius: 6px;
				font-size: 34rpx;
				color: #333;
				
				.nav-item {
					width: 100%;
					display: flex;
					align-items: center;
					margin-bottom: 28rpx;
					
					.msg {
						font-size: 34rpx;
						color: #333;
						margin-left: 12rpx;
					}
				}
			}
			
			.text {
				width: 100%;
				height: 400rpx;
				padding: 24rpx;
				box-sizing: border-box;
				background: #F1F1F1;
				line-height: 40px;
				margin-bottom: 30rpx;
				border-radius: 6px;
				font-size: 34rpx;
				color: #333;
			}
			
			.btn1 {
				width: 80%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 30rpx;
				color: #FFFFFF;
				margin: 60rpx auto 0;
				background: #005883;
				border-radius: 30px;
			}
		}
	}
</style>
